//
//  AppDelegate.m
//  FreeTime
//
//  Created by  on 16/8/26.
//  Copyright © 2016年 SRDZ.com. All rights reserved.
//

#import "AppDelegate.h"
#import "FindControl.h"
#import "MessageControl.h"
#import "LikeControl.h"
#import "MineControl.h"
#import "ImageUtil.h"
#import "Header.h"
#import "LoginControl.h"
#import "GuideControl.h"
@interface AppDelegate ()<UITabBarControllerDelegate>


@end

@implementation AppDelegate

#pragma mark -- 系统方法 --
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    self.window.backgroundColor = [UIColor whiteColor];
    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstStart"]){
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstStart"];
        NSLog(@"第一次启动");
        self.window.rootViewController = [self setupGuide];
    }else{
        NSLog(@"不是第一次启动");
        self.window.rootViewController = [self creatTab];
    }

    
    [self.window makeKeyAndVisible];
    
    
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
#pragma mark -- selfStyle --
- (UIViewController *)setupGuide{
    GuideControl * guide = [GuideControl new];
    return guide;
}
- (UITabBarController *)creatTab{
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];//隐藏返回按钮带的字
    FindControl * findVC = [[FindControl alloc] init];
    UINavigationController * nav1 = [[UINavigationController alloc] initWithRootViewController:findVC];
    nav1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"发现" image:[UIImage imageNamed:@"discover_nor"] selectedImage:[UIImage imageNamed:@"discover_li"]];
    [nav1.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -2)];
    
    MessageControl * messageVC = [[MessageControl alloc] init];
    UINavigationController * nav2 = [[UINavigationController alloc] initWithRootViewController:messageVC];
    nav2.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"聊天" image:[UIImage imageNamed:@"message_nor"] selectedImage:[UIImage imageNamed:@"message_li"]];
    [nav2.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -2)];
    
    LikeControl *likeVC = [[LikeControl alloc]init];
    UINavigationController * nav3 = [[UINavigationController alloc] initWithRootViewController:likeVC];//btn_fenlei_li
    nav3.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"喜欢的人" image:[UIImage imageNamed:@"like_nor"] selectedImage:[UIImage imageNamed:@"like_li"]];
    [nav3.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -2)];
    
    MineControl *mineVC = [[MineControl alloc]init];
    UINavigationController * nav4 = [[UINavigationController alloc] initWithRootViewController:mineVC];//btn_fenlei_li
    
    nav4.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"个人中心" image:[UIImage imageNamed:@"mine_nor"] selectedImage:[UIImage imageNamed:@"mine_li"]];
    [nav4.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -2)];
    
    self.tab = [[UITabBarController alloc] init];
    _tab.viewControllers = @[nav1,nav2,nav3,nav4];
    _tab.delegate = self;
    _tab.tabBar.tintColor = HOME_COLOR;
    
    return _tab;
}
//- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
//    if ([viewController.tabBarItem.title isEqualToString:@"聊天"]) {
//        if (1 != 0) {
////            NSLog(@"%@",[]);
//            [viewController presentViewController:[LoginControl new] animated:YES completion:nil];
//            return NO;
//        }
//    }
    
//    return YES;
//}


@end
